package com.example.demo.service.impl;

import com.example.demo.dao.StudentDao;
import com.example.demo.entity.Student;
import com.example.demo.service.StudentService;
import com.example.demo.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/4/16/19:08
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    StudentDao studentDao;

    @Override
    public Result selectAll(Integer current, Integer pageSize) {
        PageHelper.startPage(current,pageSize);
        List<Student> students = studentDao.selectAll();
        System.out.println(students);
        PageInfo<Student> pageInfo=new PageInfo<>(students);
        return new Result(200,"查询成功",pageInfo);
    }

    @Override
    public Result insertStudent(Student student) {
        int i = studentDao.insertStudent(student);
        return new Result(200,"添加成功",i);
    }

    @Override
    public Result deleteById(Integer id) {
        int i = studentDao.deleteById(id);
        return new Result(200,"删除成功",i);
    }

    @Override
    public Result update(Student student) {
        int i = studentDao.update(student);
        return new Result(200,"修改成功",i);
    }
}
